<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 不同整数的最少数目 -->
    <script>
      var findLeastNumOfUniqueInts = function (arr, k) {
        var obj = {}
        var num = 0
        // 去重
        for (var i = 0; i < arr.length; i++) {
          obj[arr[i]] = obj[arr[i]] >= 0 ? obj[arr[i]] + 1 : 1
        }
        // 排序
        var sortArr = Object.values(obj).sort((a, b) => a - b)
        // 从升序数组最小数目删除
        for (var i = 0; i < sortArr.length; i++) {
          num++
          if (k >= sortArr[i]) {
            k = k - sortArr[i]
            num--
          }
        }
        return num
      }
      console.log(findLeastNumOfUniqueInts([5, 5, 4], 1))
    </script>
  </body>
</html>
